<template>
  <div>
    <el-form :model="queryForm"  :inline = true @submit.native.prevent >
      <el-form-item label="玩家号" prop="inviteCode">
        <el-input  v-model="queryForm.inviteCode" placeholder="请输入玩家号" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="getList">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="headPortrait" label="头像" width="180" align="center">
          <template #default="scope">
            <image-preview :src="scope.row.headPortrait" :width="100" :height="100"/>
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="用户昵称" align="center"></el-table-column>
        <el-table-column prop="inviteCode" label="玩家号" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="180">
          <template #default="scope">
            <el-button @click="handleClick(scope.row)" icon="el-icon-unlock" type="text" >解除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { ref, reactive, watch } from 'vue';
import { getLockUserCollageList, removeLockUserCollage } from '@/api/workflow/cardCollage/index';
export default {
  name: 'nonPayment',
  props: {
    collageId: {
      default: '',
      type: String,
    }
  },
  setup(props) {
    const queryForm = reactive({
      inviteCode: '',
      collageId: props.collageId,
    });

    const tableData = ref([]);

    const getList = () => {
      if(queryForm.inviteCode == '' || queryForm.inviteCode == undefined || queryForm.inviteCode == null) {
        ElMessage.error('玩家号不能为空')
      } else {
        getLockUserCollageList(queryForm).then((res) => {
          tableData.value = res;
        });
      }
    };

    const handleClick = (row) => {
      ElMessageBox.confirm('您确定要解除该用户的锁单限制?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeLockUserCollage({ collageId: props.collageId, inviteCode: row.inviteCode }).then((res) => {
          if (res.code === 200) {
            ElMessage.success(res.msg);
            getList();
          }
        });
      }).catch(() => {});
    };

    const resetQuery = () => {
      queryForm.inviteCode = '';
      tableData.value = [];
    };

    watch(
      () => props.collageId,
      (newVal) => {
        queryForm.collageId = newVal;
      },
      { immediate: true }
    );

    return {
      queryForm,
      tableData,
      getList,
      handleClick,
      resetQuery,
    };
  }
};

</script>

<style scoped>
/* 样式部分不变 */
</style>
